package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.characteristic.TrackCharacteristic;
import com.xmy.cultivate.entity.TrackDetail;
import com.xmy.cultivate.entity.TrackMarket;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.PageResult;
import com.xmy.cultivate.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


@RestController
@RequestMapping("/api/trackMarket")
public class TrackMarketController extends BaseController {

    private final Integer trackType = 1;


    @Resource
    TrackCharacteristic trackCharacteristic;


    @GetMapping()
    public Result findAll(@RequestParam Map<String, String> reMap) {
        IPage<TrackMarket> iPage = trackCharacteristic.findAll(reMap, this.trackType);
        return new Result(Code.GET_OK, new PageResult(iPage.getRecords(), iPage.getTotal(), iPage.getPages()), Code.GET_OK_MSG);
    }


    @GetMapping(value = "/{id}", name = "course:findbyid")
    public Result findById(@PathVariable(value = "id") Long id) {
        return trackCharacteristic.findById(id);
    }

    @PostMapping()
    public Result save(@RequestBody TrackMarket trackMarket) {
        return trackCharacteristic.save(trackMarket, this.trackType);
    }

    @PutMapping("/{id}")
    public Result update(@RequestBody TrackMarket trackMarket) {
        return trackCharacteristic.update(trackMarket);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable(value = "id") Long id) {
        return trackCharacteristic.delete(id);
    }

    @PostMapping("/addBatchSourse")
    public Result addBatchSourse(@RequestBody TrackDetail trackDetail) {
        return trackCharacteristic.addBatchSourse(trackDetail);
    }

    @DeleteMapping("/deleteBatchSourse")
    public Result deleteBatchSourse(@RequestBody TrackMarket trackMarket) {
        return trackCharacteristic.deleteBatchSourse(trackMarket);
    }


    /**
     * @param reMap
     * @param schoolIdList
     * @param isRepetition 是否允许重复
     * @return
     */
    @GetMapping("checkTeacher")
    public Result checkTeacher(@RequestParam Map<String, String> reMap,
                               @RequestParam(value = "schoolIdList", defaultValue = "") String[] schoolIdList,
                               @RequestParam(value = "isRepetition", required = false) String isRepetition) {
        return trackCharacteristic.checkTeacher(reMap, schoolIdList, isRepetition);
    }

    @GetMapping("checkSchool")
    public Result checkSchool(@RequestParam Map<String, Object> reMap) {
        return trackCharacteristic.checkSchool(reMap);
    }

}
